package demo4;

import com.sun.xml.internal.ws.addressing.WsaTubeHelper;

import java.util.Arrays;
import java.util.Comparator;
/*class Students implements Comparable<Students>{
    public int age;
    public String name;
    public double score;

    public Students(int age, String name, double score) {
        this.age = age;
        this.name = name;
        this.score = score;
    }
    @Override
    public String toString() {
        return "Students{" +
                "age=" + age +
                ", name='" + name + '\'' +
                ", score=" + score +
                '}';
    }
    @Override
    public int compareTo(Students o) {
       *//* if (this.age>o.age){
            return 1;
        }else if (this.age==o.age){
            return 0;
        }else{
            return -1;
        }*//*
        //return this.age-o.age;
        return this.name.compareTo(o.name);
    }
}*/

class Students {
    public int age;
    public String name;
    public double score;

    public Students(int age, String name, double score) {
        this.age = age;
        this.name = name;
        this.score = score;
    }
    @Override
    public String toString() {
        return "Students{" +
                "age=" + age +
                ", name='" + name + '\'' +
                ", score=" + score +
                '}';
    }
}
class AgeComparator implements Comparator<Students> {
    @Override
    public int compare(Students o1, Students o2) {
        return o1.age-o2.age;
    }
}
class ScoreComparator implements Comparator<Students>{
    @Override
    public int compare(Students o1, Students o2) {
        return (int)(o1.score-o2.score);
    }
}
public class test {
    public static void main2(String[] args) {
        Students students1=new Students(12,"bit",99.3);
        Students students2=new Students(15,"abc",98.9);
       // System.out.println(students1.compareTo(students2));
        AgeComparator ageComparator=new AgeComparator();
        System.out.println(ageComparator.compare(students1,students2));
    }
    public static void main(String[] args) {
        Students[] students=new Students[3];
        students[0]=new Students(12,"bit",99.3);
        students[1]=new Students(15,"abc",18.9);
        students[2]=new Students(18,"zhangsan",102);
        System.out.println(Arrays.toString(students));
        AgeComparator ageComparator=new AgeComparator();
        ScoreComparator scoreComparator=new ScoreComparator();
        Arrays.sort(students,scoreComparator);
        System.out.println(Arrays.toString(students));
    }
    public static void main1(String[] args) {
        int[] array={1,26,5,48,13};
        System.out.println(Arrays.toString(array));
        Arrays.sort(array);
        System.out.println(array);
    }
}























